home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / system-config-printer / troubleshoot / base.py < prev    next >
Encoding:
Python Source  |  2010-09-28  |  3.3 KB  |  105 lines

  1. #!/usr/bin/env python
  2.  
  3. ## Printing troubleshooter
  4.  
  5. ## Copyright (C) 2008, 2010 Red Hat, Inc.
  6. ## Authors:
  7. ##  Tim Waugh <twaugh@redhat.com>
  8.  
  9. ## This program is free software; you can redistribute it and/or modify
  10. ## it under the terms of the GNU General Public License as published by
  11. ## the Free Software Foundation; either version 2 of the License, or
  12. ## (at your option) any later version.
  13.  
  14. ## This program is distributed in the hope that it will be useful,
  15. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ## GNU General Public License for more details.
  18.  
  19. ## You should have received a copy of the GNU General Public License
  20. ## along with this program; if not, write to the Free Software
  21. ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. import gtk
  24. from gettext import gettext as _
  25. N_ = lambda x: x
  26. from debug import *
  27.  
  28. __all__ = [ 'gtk',
  29.             '_',
  30.             'debugprint', 'get_debugging', 'set_debugging',
  31.             'Question',
  32.             'Multichoice',
  33.             'TEXT_start_print_admin_tool' ]
  34.  
  35. TEXT_start_print_admin_tool = N_("To start this tool, select "
  36.                                  "System->Administration->Printing "
  37.                                  "from the main menu.")
  38.  
  39. class Question:
  40.     def __init__ (self, troubleshooter, name=None):
  41.         self.troubleshooter = troubleshooter
  42.         if name:
  43.             self.__str__ = lambda: name
  44.  
  45.     def display (self):
  46.         """Returns True if this page should be displayed, or False
  47.         if it should be skipped."""
  48.         return True
  49.  
  50.     def connect_signals (self, handler):
  51.         pass
  52.  
  53.     def disconnect_signals (self):
  54.         pass
  55.  
  56.     def can_click_forward (self):
  57.         return True
  58.  
  59.     def collect_answer (self):
  60.         return {}
  61.  
  62.     def cancel_operation (self):
  63.         pass
  64.  
  65.     ## Helper functions
  66.     def initial_vbox (self, title='', text=''):
  67.         vbox = gtk.VBox ()
  68.         vbox.set_border_width (12)
  69.         vbox.set_spacing (12)
  70.         if title:
  71.             s = '<span weight="bold" size="larger">' + title + '</span>\n\n'
  72.         else:
  73.             s = ''
  74.         s += text
  75.         label = gtk.Label (s)
  76.         label.set_alignment (0, 0)
  77.         label.set_line_wrap (True)
  78.         label.set_use_markup (True)
  79.         vbox.pack_start (label, False, False, 0)
  80.         return vbox
  81.  
  82. class Multichoice(Question):
  83.     def __init__ (self, troubleshooter, question_tag, question_title,
  84.                   question_text, choices, name=None):
  85.         Question.__init__ (self, troubleshooter, name)
  86.         page = self.initial_vbox (question_title, question_text)
  87.         choice_vbox = gtk.VBox ()
  88.         choice_vbox.set_spacing (6)
  89.         page.pack_start (choice_vbox, False, False, 0)
  90.         self.question_tag = question_tag
  91.         self.widgets = []
  92.         for choice, tag in choices:
  93.             button = gtk.RadioButton (label=choice)
  94.             if len (self.widgets) > 0:
  95.                 button.set_group (self.widgets[0][0])
  96.             choice_vbox.pack_start (button, False, False, 0)
  97.             self.widgets.append ((button, tag))
  98.  
  99.         troubleshooter.new_page (page, self)
  100.  
  101.     def collect_answer (self):
  102.         for button, answer_tag in self.widgets:
  103.             if button.get_active ():
  104.                 return { self.question_tag: answer_tag }
  105.